{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.0.2\n"
     ]
    }
   ],
   "source": [
    "import tushare as ts\n",
    "import pandas as pd\n",
    "import time\n",
    "from datetime import datetime, timedelta\n",
    "\n",
    "print(ts.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#test tushare\n",
    "def allowStkCounts(userCount, open):\n",
    "    h = 1\n",
    "    while userCount > open*100*h :\n",
    "        h = h + 1\n",
    "        \n",
    "    return (h-1)*100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             open   high  close    low     volume  price_change  p_change  \\\n",
      "date                                                                        \n",
      "2017-11-03  10.92  12.09  12.09  10.83  524391.25           1.1     10.01   \n",
      "\n",
      "               ma5    ma10    ma20      v_ma5     v_ma10     v_ma20  turnover  \n",
      "date                                                                           \n",
      "2017-11-03  11.188  11.297  11.542  295165.86  235711.72  293227.01      5.39  \n"
     ]
    }
   ],
   "source": [
    "# allData = ts.get_hist_data('002156',start='2015-01-01');\n",
    "# allData.to_csv('002156.csv',index=True)\n",
    "# print(allData.head(1));\n",
    "# print(allData.head(1)['v_ma20']);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "idx:2015-01-06, yesterday close:8.08, today close:8.24, ma20:8.375\n",
      "idx:2015-01-07, yesterday close:8.24, today close:8.16, ma20:8.346\n",
      "idx:2015-01-08, yesterday close:8.16, today close:8.15, ma20:8.342\n",
      "idx:2015-01-09, yesterday close:8.15, today close:8.17, ma20:8.326\n",
      "idx:2015-01-13, yesterday close:8.02, today close:8.27, ma20:8.283\n",
      "idx:2015-01-14, yesterday close:8.27, today close:8.32, ma20:8.256\n",
      "2015-01-14买入，open: 8.27，账户剩余：152.00，持仓：2400.00，总资产：20000.00\n",
      "idx:2015-01-15, yesterday close:8.32, today close:8.36, ma20:8.236\n",
      "idx:2015-01-16, yesterday close:8.36, today close:8.34, ma20:8.206\n",
      "idx:2015-01-20, yesterday close:8.07, today close:8.59, ma20:8.169\n",
      "2015-01-20卖出，open: 8.12，账户剩余：19640.00，持仓： 0.00\n",
      "idx:2015-01-21, yesterday close:8.59, today close:8.76, ma20:8.211\n",
      "2015-01-21买入，open: 8.58，账户剩余：764.00，持仓：2200.00，总资产：19640.00\n",
      "idx:2015-01-22, yesterday close:8.76, today close:9.1, ma20:8.277\n",
      "idx:2015-01-23, yesterday close:9.1, today close:8.96, ma20:8.31\n",
      "idx:2015-01-27, yesterday close:9.38, today close:9.47, ma20:8.428\n",
      "idx:2015-01-28, yesterday close:9.47, today close:9.8, ma20:8.509\n",
      "idx:2015-01-29, yesterday close:9.8, today close:10.63, ma20:8.645\n",
      "idx:2015-01-30, yesterday close:10.63, today close:10.63, ma20:8.775\n",
      "idx:2015-02-03, yesterday close:10.58, today close:11.25, ma20:9.051\n",
      "idx:2015-02-04, yesterday close:11.25, today close:11.07, ma20:9.196\n",
      "idx:2015-02-05, yesterday close:11.07, today close:10.51, ma20:9.314\n",
      "idx:2015-02-06, yesterday close:10.51, today close:10.25, ma20:9.418\n",
      "idx:2015-02-10, yesterday close:10.12, today close:10.36, ma20:9.628\n",
      "idx:2015-02-11, yesterday close:10.36, today close:10.73, ma20:9.748\n",
      "idx:2015-02-12, yesterday close:10.73, today close:10.5, ma20:9.855\n",
      "idx:2015-02-13, yesterday close:10.5, today close:10.62, ma20:9.969\n",
      "idx:2015-02-17, yesterday close:11.4, today close:11.23, ma20:10.268\n",
      "idx:2015-02-25, yesterday close:11.38, today close:10.87, ma20:10.487\n",
      "idx:2015-02-26, yesterday close:10.87, today close:10.99, ma20:10.589\n",
      "idx:2015-02-27, yesterday close:10.99, today close:10.95, ma20:10.667\n",
      "idx:2015-03-03, yesterday close:11.31, today close:11.33, ma20:10.836\n",
      "idx:2015-03-04, yesterday close:11.33, today close:11.42, ma20:10.875\n",
      "idx:2015-03-05, yesterday close:11.42, today close:11.0, ma20:10.894\n",
      "idx:2015-03-06, yesterday close:11.0, today close:10.58, ma20:10.894\n",
      "idx:2015-03-10, yesterday close:10.68, today close:10.93, ma20:10.858\n",
      "2015-03-10卖出，open:10.69，账户剩余：24282.00，持仓： 0.00\n",
      "idx:2015-03-11, yesterday close:10.93, today close:10.86, ma20:10.876\n",
      "2015-03-11买入，open:10.93，账户剩余：236.00，持仓：2200.00，总资产：24282.00\n",
      "idx:2015-03-12, yesterday close:10.86, today close:10.52, ma20:10.889\n",
      "2015-03-12卖出，open:10.83，账户剩余：24062.00，持仓： 0.00\n",
      "idx:2015-03-13, yesterday close:10.52, today close:11.08, ma20:10.937\n",
      "idx:2015-03-17, yesterday close:11.33, today close:11.55, ma20:11.027\n",
      "2015-03-17买入，open:11.49，账户剩余：1082.00，持仓：2000.00，总资产：24062.00\n",
      "idx:2015-03-18, yesterday close:11.55, today close:12.18, ma20:11.111\n",
      "idx:2015-03-19, yesterday close:12.18, today close:11.93, ma20:11.176\n",
      "idx:2015-03-20, yesterday close:11.93, today close:12.11, ma20:11.212\n",
      "idx:2015-03-24, yesterday close:12.29, today close:12.05, ma20:11.298\n",
      "idx:2015-03-25, yesterday close:12.05, today close:12.18, ma20:11.364\n",
      "idx:2015-03-26, yesterday close:12.18, today close:12.72, ma20:11.45\n",
      "idx:2015-03-27, yesterday close:12.72, today close:13.68, ma20:11.587\n",
      "idx:2015-03-31, yesterday close:13.29, today close:13.43, ma20:11.791\n",
      "idx:2015-04-01, yesterday close:13.43, today close:13.99, ma20:11.919\n",
      "idx:2015-04-02, yesterday close:13.99, today close:14.06, ma20:12.072\n",
      "idx:2015-04-03, yesterday close:14.06, today close:14.1, ma20:12.248\n",
      "idx:2015-04-08, yesterday close:14.3, today close:13.68, ma20:12.567\n",
      "idx:2015-04-09, yesterday close:13.68, today close:13.5, ma20:12.699\n",
      "idx:2015-04-10, yesterday close:13.5, today close:13.99, ma20:12.872\n",
      "idx:2015-04-14, yesterday close:14.17, today close:13.79, ma20:13.15\n",
      "idx:2015-04-15, yesterday close:13.79, today close:14.57, ma20:13.301\n",
      "idx:2015-04-16, yesterday close:14.57, today close:15.11, ma20:13.447\n",
      "idx:2015-04-17, yesterday close:15.11, today close:14.78, ma20:13.59\n",
      "idx:2015-04-21, yesterday close:14.0, today close:14.38, ma20:13.789\n",
      "idx:2015-04-22, yesterday close:14.38, today close:14.49, ma20:13.911\n",
      "idx:2015-04-23, yesterday close:14.49, today close:14.68, ma20:14.036\n",
      "idx:2015-04-24, yesterday close:14.68, today close:14.97, ma20:14.148\n",
      "idx:2015-04-28, yesterday close:14.8, today close:14.4, ma20:14.26\n",
      "idx:2015-04-29, yesterday close:14.4, today close:15.13, ma20:14.345\n",
      "idx:2015-04-30, yesterday close:15.13, today close:15.51, ma20:14.421\n",
      "idx:2015-05-05, yesterday close:15.72, today close:15.01, ma20:14.549\n",
      "idx:2015-05-06, yesterday close:15.01, today close:14.61, ma20:14.565\n",
      "idx:2015-05-07, yesterday close:14.61, today close:14.43, ma20:14.602\n",
      "idx:2015-05-08, yesterday close:14.43, today close:14.98, ma20:14.676\n",
      "2015-05-08卖出，open:14.60，账户剩余：30282.00，持仓： 0.00\n",
      "idx:2015-05-12, yesterday close:15.75, today close:16.29, ma20:14.87\n",
      "2015-05-12买入，open:16.36，账户剩余：834.00，持仓：1800.00，总资产：30282.00\n",
      "idx:2015-05-13, yesterday close:16.29, today close:16.6, ma20:15.011\n",
      "idx:2015-05-14, yesterday close:16.6, today close:17.11, ma20:15.138\n",
      "idx:2015-05-15, yesterday close:17.11, today close:16.45, ma20:15.205\n",
      "idx:2015-05-19, yesterday close:16.34, today close:16.82, ma20:15.424\n",
      "idx:2015-05-20, yesterday close:16.82, today close:17.04, ma20:15.557\n",
      "idx:2015-05-21, yesterday close:17.04, today close:18.18, ma20:15.741\n",
      "idx:2015-05-22, yesterday close:18.18, today close:18.9, ma20:15.952\n",
      "idx:2015-05-26, yesterday close:19.81, today close:21.79, ma20:16.544\n",
      "idx:2015-05-27, yesterday close:21.79, today close:22.2, ma20:16.934\n",
      "idx:2015-05-28, yesterday close:22.2, today close:20.1, ma20:17.182\n",
      "idx:2015-05-29, yesterday close:20.1, today close:21.4, ma20:17.477\n",
      "idx:2015-06-02, yesterday close:23.54, today close:25.89, ma20:18.412\n",
      "idx:2015-06-03, yesterday close:25.89, today close:26.27, ma20:18.995\n",
      "idx:2015-06-04, yesterday close:26.27, today close:28.9, ma20:19.718\n",
      "idx:2015-06-05, yesterday close:28.9, today close:29.58, ma20:20.448\n",
      "idx:2015-06-09, yesterday close:26.63, today close:26.5, ma20:21.503\n",
      "idx:2015-06-10, yesterday close:26.5, today close:26.7, ma20:22.008\n",
      "idx:2015-06-11, yesterday close:26.7, today close:27.28, ma20:22.516\n",
      "idx:2015-06-12, yesterday close:27.28, today close:26.75, ma20:23.031\n",
      "idx:2015-06-16, yesterday close:24.93, today close:22.88, ma20:23.764\n",
      "idx:2015-06-17, yesterday close:22.88, today close:25.05, ma20:24.164\n",
      "2015-06-17卖出，open:22.86，账户剩余：41982.00，持仓： 0.00\n",
      "idx:2015-06-18, yesterday close:25.05, today close:24.22, ma20:24.466\n",
      "2015-06-18买入，open:24.74，账户剩余：2398.00，持仓：1600.00，总资产：41982.00\n",
      "idx:2015-06-19, yesterday close:24.22, today close:22.86, ma20:24.664\n",
      "2015-06-19卖出，open:22.61，账户剩余：38574.00，持仓： 0.00\n",
      "idx:2015-06-24, yesterday close:23.07, today close:23.8, ma20:24.928\n",
      "idx:2015-06-25, yesterday close:23.8, today close:22.22, ma20:24.929\n",
      "idx:2015-06-26, yesterday close:22.22, today close:20.0, ma20:24.924\n",
      "idx:2015-06-30, yesterday close:18.0, today close:18.66, ma20:24.51\n",
      "idx:2015-07-01, yesterday close:18.66, today close:17.71, ma20:24.101\n",
      "idx:2015-07-02, yesterday close:17.71, today close:15.94, ma20:23.584\n",
      "idx:2015-07-03, yesterday close:15.94, today close:14.35, ma20:22.857\n",
      "idx:2015-07-07, yesterday close:12.92, today close:11.63, ma20:21.274\n",
      "idx:2015-07-15, yesterday close:12.79, today close:14.07, ma20:19.957\n",
      "idx:2015-07-16, yesterday close:14.07, today close:14.89, ma20:19.337\n",
      "idx:2015-07-17, yesterday close:14.89, today close:16.38, ma20:18.819\n",
      "idx:2015-07-21, yesterday close:16.66, today close:16.76, ma20:18.099\n",
      "idx:2015-07-22, yesterday close:16.76, today close:17.03, ma20:17.698\n",
      "idx:2015-07-23, yesterday close:17.03, today close:17.77, ma20:17.376\n",
      "idx:2015-07-24, yesterday close:17.77, today close:17.58, ma20:17.112\n",
      "2015-07-24买入，open:18.00，账户剩余：774.00，持仓：2100.00，总资产：38574.00\n",
      "idx:2015-07-28, yesterday close:15.82, today close:14.61, ma20:16.29\n",
      "2015-07-28卖出，open:14.24，账户剩余：30678.00，持仓： 0.00\n",
      "idx:2015-07-29, yesterday close:14.61, today close:15.79, ma20:15.968\n",
      "idx:2015-07-30, yesterday close:15.79, today close:15.92, ma20:15.764\n",
      "2015-07-30买入，open:15.73，账户剩余：791.00，持仓：1900.00，总资产：30678.00\n",
      "idx:2015-07-31, yesterday close:15.92, today close:15.9, ma20:15.659\n",
      "idx:2015-08-04, yesterday close:14.9, today close:16.28, ma20:15.4\n",
      "2015-08-04卖出，open:14.98，账户剩余：29253.00，持仓： 0.00\n",
      "idx:2015-08-05, yesterday close:16.28, today close:15.97, ma20:15.401\n",
      "2015-08-05买入，open:16.22，账户剩余：57.00，持仓：1800.00，总资产：29253.00\n",
      "idx:2015-08-06, yesterday close:15.97, today close:15.64, ma20:15.466\n",
      "idx:2015-08-07, yesterday close:15.64, today close:16.61, ma20:15.65\n",
      "2015-08-07卖出，open:15.90，账户剩余：28677.00，持仓： 0.00\n",
      "idx:2015-09-17, yesterday close:15.73, today close:14.16, ma20:16.094\n",
      "idx:2015-09-18, yesterday close:14.16, today close:12.74, ma20:15.987\n",
      "idx:2015-09-22, yesterday close:12.59, today close:13.03, ma20:15.616\n",
      "idx:2015-09-23, yesterday close:13.03, today close:12.49, ma20:15.402\n",
      "idx:2015-09-24, yesterday close:12.49, today close:12.92, ma20:15.197\n",
      "idx:2015-09-25, yesterday close:12.92, today close:12.11, ma20:14.914\n",
      "idx:2015-09-29, yesterday close:12.14, today close:11.84, ma20:14.443\n",
      "idx:2015-09-30, yesterday close:11.84, today close:12.43, ma20:14.334\n",
      "idx:2015-10-08, yesterday close:12.44, today close:13.17, ma20:14.029\n",
      "idx:2015-10-09, yesterday close:13.17, today close:13.15, ma20:13.891\n",
      "idx:2015-10-13, yesterday close:14.02, today close:14.6, ma20:13.763\n",
      "2015-10-13买入，open:13.96，账户剩余：757.00，持仓：2000.00，总资产：28677.00\n",
      "idx:2015-10-14, yesterday close:14.6, today close:14.32, ma20:13.681\n",
      "idx:2015-10-15, yesterday close:14.32, today close:15.5, ma20:13.674\n",
      "idx:2015-10-30, yesterday close:15.9, today close:14.95, ma20:13.512\n",
      "idx:2015-11-03, yesterday close:14.47, today close:14.41, ma20:13.461\n",
      "idx:2015-11-04, yesterday close:14.41, today close:15.15, ma20:13.582\n",
      "idx:2015-11-05, yesterday close:15.15, today close:14.94, ma20:13.699\n",
      "idx:2015-11-06, yesterday close:14.94, today close:16.43, ma20:13.869\n",
      "idx:2015-11-10, yesterday close:16.88, today close:16.77, ma20:14.281\n",
      "idx:2015-11-11, yesterday close:16.77, today close:16.91, ma20:14.521\n",
      "idx:2015-11-12, yesterday close:16.91, today close:16.58, ma20:14.743\n",
      "idx:2015-11-13, yesterday close:16.58, today close:15.71, ma20:14.937\n",
      "idx:2015-11-17, yesterday close:16.24, today close:15.9, ma20:15.3\n",
      "idx:2015-11-18, yesterday close:15.9, today close:15.84, ma20:15.434\n",
      "idx:2015-11-19, yesterday close:15.84, today close:17.13, ma20:15.633\n",
      "idx:2015-11-20, yesterday close:17.13, today close:18.08, ma20:15.836\n",
      "idx:2015-11-24, yesterday close:17.72, today close:19.49, ma20:16.25\n",
      "idx:2015-11-25, yesterday close:19.49, today close:20.12, ma20:16.481\n",
      "idx:2015-11-26, yesterday close:20.12, today close:21.85, ma20:16.779\n",
      "idx:2015-11-27, yesterday close:21.85, today close:19.88, ma20:17.025\n",
      "idx:2015-12-01, yesterday close:20.0, today close:18.8, ma20:17.521\n",
      "idx:2015-12-02, yesterday close:18.8, today close:18.18, ma20:17.673\n",
      "idx:2015-12-03, yesterday close:18.18, today close:18.81, ma20:17.866\n",
      "idx:2015-12-04, yesterday close:18.81, today close:19.09, ma20:17.999\n",
      "idx:2015-12-08, yesterday close:19.03, today close:19.09, ma20:18.223\n",
      "idx:2015-12-09, yesterday close:19.09, today close:18.45, ma20:18.3\n",
      "idx:2015-12-10, yesterday close:18.45, today close:18.6, ma20:18.401\n",
      "idx:2015-12-11, yesterday close:18.6, today close:19.2, ma20:18.575\n",
      "idx:2015-12-15, yesterday close:19.21, today close:19.5, ma20:18.904\n",
      "idx:2015-12-16, yesterday close:19.5, today close:20.2, ma20:19.122\n",
      "idx:2015-12-17, yesterday close:20.2, today close:20.37, ma20:19.284\n",
      "idx:2015-12-18, yesterday close:20.37, today close:19.7, ma20:19.365\n",
      "idx:2015-12-22, yesterday close:19.55, today close:19.39, ma20:19.451\n",
      "idx:2015-12-23, yesterday close:19.39, today close:18.76, ma20:19.383\n",
      "idx:2015-12-24, yesterday close:18.76, today close:18.98, ma20:19.24\n",
      "2015-12-24卖出，open:18.41，账户剩余：37577.00，持仓： 0.00\n",
      "idx:2015-12-25, yesterday close:18.98, today close:19.12, ma20:19.202\n",
      "idx:2015-12-29, yesterday close:18.4, today close:18.59, ma20:19.111\n",
      "idx:2015-12-30, yesterday close:18.59, today close:19.7, ma20:19.187\n",
      "idx:2015-12-31, yesterday close:19.7, today close:19.09, ma20:19.201\n",
      "2015-12-31买入，open:19.59，账户剩余：356.00，持仓：1900.00，总资产：37577.00\n",
      "idx:2016-01-05, yesterday close:17.18, today close:15.46, ma20:18.927\n",
      "2016-01-05卖出，open:15.56，账户剩余：29920.00，持仓： 0.00\n",
      "idx:2016-01-06, yesterday close:15.46, today close:16.27, ma20:18.786\n",
      "idx:2016-01-07, yesterday close:16.27, today close:14.64, ma20:18.596\n",
      "idx:2016-01-08, yesterday close:14.64, today close:14.53, ma20:18.392\n",
      "idx:2016-01-12, yesterday close:13.08, today close:12.75, ma20:17.763\n",
      "idx:2016-01-13, yesterday close:12.75, today close:12.24, ma20:17.4\n",
      "idx:2016-01-14, yesterday close:12.24, today close:12.71, ma20:17.026\n",
      "idx:2016-01-15, yesterday close:12.71, today close:11.99, ma20:16.607\n",
      "idx:2016-01-19, yesterday close:12.35, today close:13.04, ma20:15.914\n",
      "idx:2016-01-20, yesterday close:13.04, today close:12.86, ma20:15.587\n",
      "idx:2016-01-21, yesterday close:12.86, today close:12.2, ma20:15.259\n",
      "idx:2016-01-22, yesterday close:12.2, today close:12.42, ma20:14.931\n",
      "idx:2016-01-26, yesterday close:12.67, today close:11.4, ma20:14.259\n",
      "idx:2016-01-27, yesterday close:11.4, today close:10.98, ma20:13.878\n",
      "idx:2016-01-28, yesterday close:10.98, today close:10.17, ma20:13.402\n",
      "idx:2016-01-29, yesterday close:10.17, today close:10.83, ma20:12.989\n",
      "idx:2016-02-02, yesterday close:10.8, today close:11.24, ma20:12.459\n",
      "idx:2016-02-03, yesterday close:11.24, today close:11.26, ma20:12.208\n",
      "idx:2016-02-04, yesterday close:11.26, today close:11.85, ma20:12.069\n",
      "idx:2016-02-05, yesterday close:11.85, today close:11.61, ma20:11.923\n",
      "idx:2016-02-16, yesterday close:11.36, today close:12.05, ma20:11.802\n",
      "idx:2016-02-17, yesterday close:12.05, today close:12.27, ma20:11.803\n",
      "2016-02-17买入，open:12.00，账户剩余：1120.00，持仓：2400.00，总资产：29920.00\n",
      "idx:2016-02-18, yesterday close:12.27, today close:12.24, ma20:11.78\n",
      "idx:2016-02-19, yesterday close:12.24, today close:12.49, ma20:11.805\n",
      "idx:2016-02-23, yesterday close:13.2, today close:13.57, ma20:11.874\n",
      "idx:2016-02-24, yesterday close:13.57, today close:13.24, ma20:11.893\n",
      "idx:2016-02-25, yesterday close:13.24, today close:11.92, ma20:11.879\n",
      "idx:2016-02-26, yesterday close:11.92, today close:12.16, ma20:11.866\n",
      "idx:2016-03-01, yesterday close:11.06, today close:11.37, ma20:11.784\n",
      "2016-03-01卖出，open:11.16，账户剩余：27904.00，持仓： 0.00\n",
      "idx:2016-03-02, yesterday close:11.37, today close:12.05, ma20:11.837\n",
      "idx:2016-03-03, yesterday close:12.05, today close:12.09, ma20:11.933\n",
      "2016-03-03买入，open:12.10，账户剩余：74.00，持仓：2300.00，总资产：27904.00\n",
      "idx:2016-03-04, yesterday close:12.09, today close:11.31, ma20:11.957\n",
      "idx:2016-03-08, yesterday close:11.6, today close:11.7, ma20:12.02\n",
      "2016-03-08卖出，open:11.53，账户剩余：26593.00，持仓： 0.00\n",
      "idx:2016-03-09, yesterday close:11.7, today close:11.31, ma20:12.023\n",
      "idx:2016-03-10, yesterday close:11.31, today close:11.0, ma20:11.98\n",
      "idx:2016-03-11, yesterday close:11.0, today close:11.0, ma20:11.95\n",
      "idx:2016-03-15, yesterday close:11.49, today close:11.36, ma20:11.922\n",
      "idx:2016-03-16, yesterday close:11.36, today close:11.7, ma20:11.893\n",
      "idx:2016-03-17, yesterday close:11.7, today close:12.51, ma20:11.907\n",
      "idx:2016-03-18, yesterday close:12.51, today close:13.08, ma20:11.936\n",
      "2016-03-18买入，open:12.52，账户剩余：301.00，持仓：2100.00，总资产：26593.00\n",
      "idx:2016-03-22, yesterday close:13.25, today close:13.26, ma20:11.923\n",
      "idx:2016-03-23, yesterday close:13.26, today close:13.22, ma20:11.922\n",
      "idx:2016-03-24, yesterday close:13.22, today close:13.07, ma20:11.98\n",
      "idx:2016-03-25, yesterday close:13.07, today close:13.39, ma20:12.041\n",
      "idx:2016-03-29, yesterday close:13.12, today close:12.74, ma20:12.213\n",
      "idx:2016-03-30, yesterday close:12.74, today close:13.39, ma20:12.28\n",
      "idx:2016-03-31, yesterday close:13.39, today close:13.51, ma20:12.351\n",
      "idx:2016-04-01, yesterday close:13.51, today close:13.45, ma20:12.458\n",
      "idx:2016-04-06, yesterday close:14.37, today close:14.16, ma20:12.719\n",
      "idx:2016-04-07, yesterday close:14.16, today close:13.6, ma20:12.834\n",
      "idx:2016-04-08, yesterday close:13.6, today close:13.54, ma20:12.961\n",
      "idx:2016-04-12, yesterday close:13.67, today close:13.42, ma20:13.191\n",
      "idx:2016-04-13, yesterday close:13.42, today close:13.78, ma20:13.312\n",
      "idx:2016-04-14, yesterday close:13.78, today close:13.94, ma20:13.424\n",
      "idx:2016-04-15, yesterday close:13.94, today close:14.2, ma20:13.508\n",
      "idx:2016-04-19, yesterday close:14.48, today close:14.09, ma20:13.62\n",
      "idx:2016-04-20, yesterday close:14.09, today close:12.99, ma20:13.607\n",
      "idx:2016-04-21, yesterday close:12.99, today close:12.73, ma20:13.582\n",
      "2016-04-21卖出，open:12.83，账户剩余：27244.00，持仓： 0.00\n",
      "idx:2016-04-22, yesterday close:12.73, today close:12.93, ma20:13.575\n",
      "idx:2016-04-26, yesterday close:12.92, today close:13.06, ma20:13.549\n",
      "idx:2016-04-27, yesterday close:13.06, today close:12.83, ma20:13.553\n",
      "idx:2016-04-28, yesterday close:12.83, today close:12.88, ma20:13.528\n",
      "idx:2016-04-29, yesterday close:12.88, today close:12.79, ma20:13.492\n",
      "idx:2016-05-04, yesterday close:13.32, today close:13.49, ma20:13.441\n",
      "idx:2016-05-05, yesterday close:13.49, today close:13.62, ma20:13.414\n",
      "2016-05-05买入，open:13.41，账户剩余：424.00，持仓：2000.00，总资产：27244.00\n",
      "idx:2016-05-06, yesterday close:13.62, today close:13.1, ma20:13.389\n",
      "idx:2016-05-10, yesterday close:12.7, today close:12.51, ma20:13.289\n",
      "2016-05-10卖出，open:12.63，账户剩余：25684.00，持仓： 0.00\n",
      "idx:2016-05-11, yesterday close:12.51, today close:12.36, ma20:13.236\n",
      "idx:2016-05-12, yesterday close:12.36, today close:12.24, ma20:13.159\n",
      "idx:2016-05-13, yesterday close:12.24, today close:12.1, ma20:13.067\n",
      "idx:2016-05-17, yesterday close:12.53, today close:12.67, ma20:12.893\n",
      "idx:2016-05-18, yesterday close:12.67, today close:12.0, ma20:12.789\n",
      "idx:2016-05-19, yesterday close:12.0, today close:12.1, ma20:12.744\n",
      "idx:2016-05-20, yesterday close:12.1, today close:12.35, ma20:12.725\n",
      "idx:2016-05-24, yesterday close:12.68, today close:12.81, ma20:12.707\n",
      "idx:2016-05-25, yesterday close:12.81, today close:12.74, ma20:12.691\n",
      "2016-05-25买入，open:12.93，账户剩余：1117.00，持仓：1900.00，总资产：25684.00\n",
      "idx:2016-05-26, yesterday close:12.74, today close:12.96, ma20:12.698\n",
      "idx:2016-05-27, yesterday close:12.96, today close:14.26, ma20:12.767\n",
      "idx:2016-05-31, yesterday close:14.69, today close:11.6, ma20:12.776\n",
      "2016-05-31买入，open:11.10，账户剩余： 7.00，持仓：2000.00，总资产：22207.00\n",
      "idx:2016-06-01, yesterday close:11.6, today close:11.91, ma20:12.697\n",
      "2016-06-01卖出，open:11.50，账户剩余：23007.00，持仓： 0.00\n",
      "idx:2016-06-02, yesterday close:11.91, today close:12.04, ma20:12.618\n",
      "idx:2016-06-03, yesterday close:12.04, today close:11.93, ma20:12.559\n",
      "idx:2016-06-07, yesterday close:12.02, today close:12.4, ma20:12.52\n",
      "idx:2016-06-08, yesterday close:12.4, today close:11.93, ma20:12.498\n",
      "idx:2016-06-14, yesterday close:11.18, today close:11.36, ma20:12.408\n",
      "idx:2016-06-15, yesterday close:11.36, today close:12.09, ma20:12.386\n",
      "idx:2016-06-16, yesterday close:12.09, today close:12.39, ma20:12.372\n",
      "idx:2016-06-17, yesterday close:12.39, today close:12.62, ma20:12.403\n",
      "idx:2016-06-21, yesterday close:13.17, today close:12.73, ma20:12.476\n",
      "2016-06-21买入，open:13.00，账户剩余：907.00，持仓：1700.00，总资产：23007.00\n",
      "idx:2016-06-22, yesterday close:12.73, today close:13.03, ma20:12.493\n",
      "idx:2016-06-23, yesterday close:13.03, today close:12.66, ma20:12.486\n",
      "idx:2016-06-24, yesterday close:12.66, today close:13.93, ma20:12.545\n",
      "idx:2016-06-28, yesterday close:14.46, today close:14.08, ma20:12.611\n",
      "idx:2016-06-29, yesterday close:14.08, today close:14.02, ma20:12.578\n",
      "idx:2016-06-30, yesterday close:14.02, today close:14.1, ma20:12.703\n",
      "idx:2016-07-01, yesterday close:14.1, today close:13.52, ma20:12.783\n",
      "idx:2016-07-05, yesterday close:13.6, today close:13.71, ma20:12.95\n",
      "idx:2016-07-06, yesterday close:13.71, today close:13.47, ma20:13.023\n",
      "idx:2016-07-07, yesterday close:13.47, today close:13.88, ma20:13.097\n",
      "idx:2016-07-08, yesterday close:13.88, today close:13.68, ma20:13.184\n",
      "idx:2016-07-12, yesterday close:13.39, today close:13.2, ma20:13.387\n",
      "idx:2016-07-13, yesterday close:13.2, today close:13.27, ma20:13.446\n",
      "2016-07-13卖出，open:13.21，账户剩余：23364.00，持仓： 0.00\n",
      "idx:2016-07-14, yesterday close:13.27, today close:13.33, ma20:13.493\n",
      "idx:2016-07-15, yesterday close:13.33, today close:13.05, ma20:13.514\n",
      "idx:2016-07-19, yesterday close:13.16, today close:13.52, ma20:13.553\n",
      "idx:2016-07-20, yesterday close:13.52, today close:13.57, ma20:13.58\n",
      "idx:2016-07-21, yesterday close:13.57, today close:13.28, ma20:13.611\n",
      "idx:2016-07-22, yesterday close:13.28, today close:13.21, ma20:13.575\n",
      "idx:2016-07-26, yesterday close:13.29, today close:13.93, ma20:13.509\n",
      "idx:2016-07-27, yesterday close:13.93, today close:13.15, ma20:13.466\n",
      "2016-07-27买入，open:13.92，账户剩余：1092.00，持仓：1600.00，总资产：23364.00\n",
      "idx:2016-07-28, yesterday close:13.15, today close:12.52, ma20:13.387\n",
      "2016-07-28卖出，open:13.02，账户剩余：21924.00，持仓： 0.00\n",
      "idx:2016-07-29, yesterday close:12.52, today close:12.45, ma20:13.333\n",
      "idx:2016-08-02, yesterday close:12.15, today close:12.17, ma20:13.184\n",
      "idx:2016-08-03, yesterday close:12.17, today close:12.06, ma20:13.113\n",
      "idx:2016-08-04, yesterday close:12.06, today close:12.25, ma20:13.032\n",
      "idx:2016-08-05, yesterday close:12.25, today close:12.03, ma20:12.949\n",
      "idx:2016-08-09, yesterday close:12.17, today close:12.25, ma20:12.841\n",
      "idx:2016-08-10, yesterday close:12.25, today close:12.18, ma20:12.786\n",
      "idx:2016-08-11, yesterday close:12.18, today close:11.72, ma20:12.706\n",
      "idx:2016-11-04, yesterday close:12.89, today close:13.01, ma20:12.69\n",
      "2016-11-04买入，open:13.60，账户剩余：164.00，持仓：1600.00，总资产：21924.00\n",
      "idx:2016-11-08, yesterday close:12.51, today close:12.39, ma20:12.581\n",
      "2016-11-08卖出，open:12.69，账户剩余：20468.00，持仓： 0.00\n",
      "idx:2016-11-09, yesterday close:12.39, today close:12.16, ma20:12.525\n",
      "idx:2016-11-10, yesterday close:12.16, today close:12.29, ma20:12.479\n",
      "idx:2016-11-11, yesterday close:12.29, today close:12.37, ma20:12.433\n",
      "idx:2016-11-15, yesterday close:12.69, today close:12.6, ma20:12.343\n",
      "2016-11-15买入，open:12.55，账户剩余：388.00，持仓：1600.00，总资产：20468.00\n",
      "idx:2016-11-16, yesterday close:12.6, today close:12.4, ma20:12.337\n",
      "idx:2016-11-17, yesterday close:12.4, today close:12.35, ma20:12.332\n",
      "idx:2016-11-18, yesterday close:12.35, today close:12.18, ma20:12.334\n",
      "idx:2016-11-22, yesterday close:12.15, today close:12.14, ma20:12.337\n",
      "2016-11-22卖出，open:12.17，账户剩余：19860.00，持仓： 0.00\n",
      "idx:2016-11-23, yesterday close:12.14, today close:12.21, ma20:12.335\n",
      "idx:2016-11-24, yesterday close:12.21, today close:12.06, ma20:12.336\n",
      "idx:2016-11-25, yesterday close:12.06, today close:11.98, ma20:12.327\n",
      "idx:2016-11-29, yesterday close:12.1, today close:11.91, ma20:12.306\n",
      "idx:2016-11-30, yesterday close:11.91, today close:11.83, ma20:12.311\n",
      "idx:2016-12-01, yesterday close:11.83, today close:11.86, ma20:12.26\n",
      "idx:2016-12-02, yesterday close:11.86, today close:11.64, ma20:12.191\n",
      "idx:2016-12-06, yesterday close:11.52, today close:11.52, ma20:12.098\n",
      "idx:2016-12-07, yesterday close:11.52, today close:11.78, ma20:12.079\n",
      "idx:2016-12-08, yesterday close:11.78, today close:11.63, ma20:12.046\n",
      "idx:2016-12-09, yesterday close:11.63, today close:11.58, ma20:12.007\n",
      "idx:2016-12-13, yesterday close:11.18, today close:11.21, ma20:11.862\n",
      "idx:2016-12-14, yesterday close:11.21, today close:11.05, ma20:11.794\n",
      "idx:2016-12-15, yesterday close:11.05, today close:11.09, ma20:11.731\n",
      "idx:2016-12-16, yesterday close:11.09, today close:11.25, ma20:11.685\n",
      "idx:2016-12-20, yesterday close:11.24, today close:11.31, ma20:11.598\n",
      "idx:2016-12-21, yesterday close:11.31, today close:11.34, ma20:11.554\n",
      "idx:2016-12-22, yesterday close:11.34, today close:11.23, ma20:11.513\n",
      "idx:2016-12-23, yesterday close:11.23, today close:11.05, ma20:11.466\n",
      "idx:2016-12-27, yesterday close:11.36, today close:11.38, ma20:11.403\n",
      "idx:2017-01-06, yesterday close:11.56, today close:11.21, ma20:11.357\n",
      "2017-01-06买入，open:11.43，账户剩余：429.00，持仓：1700.00，总资产：19860.00\n",
      "idx:2017-01-10, yesterday close:11.18, today close:11.1, ma20:11.313\n",
      "2017-01-10卖出，open:11.17，账户剩余：19418.00，持仓： 0.00\n",
      "idx:2017-01-11, yesterday close:11.1, today close:11.03, ma20:11.288\n",
      "idx:2017-01-12, yesterday close:11.03, today close:10.82, ma20:11.24\n",
      "idx:2017-01-13, yesterday close:10.82, today close:10.6, ma20:11.189\n",
      "idx:2017-01-17, yesterday close:10.0, today close:10.17, ma20:11.059\n",
      "idx:2017-01-18, yesterday close:10.17, today close:10.06, ma20:11.002\n",
      "idx:2017-01-19, yesterday close:10.06, today close:10.0, ma20:10.949\n",
      "idx:2017-01-20, yesterday close:10.0, today close:10.18, ma20:10.904\n",
      "idx:2017-01-24, yesterday close:10.28, today close:10.17, ma20:10.802\n",
      "idx:2017-01-25, yesterday close:10.17, today close:10.15, ma20:10.744\n",
      "idx:2017-01-26, yesterday close:10.15, today close:10.22, ma20:10.688\n",
      "idx:2017-02-03, yesterday close:11.17, today close:10.3, ma20:10.647\n",
      "2017-02-03买入，open:10.26，账户剩余：950.00，持仓：1800.00，总资产：19418.00\n",
      "idx:2017-02-07, yesterday close:10.47, today close:10.37, ma20:10.552\n",
      "2017-02-07卖出，open:10.42，账户剩余：19706.00，持仓： 0.00\n",
      "idx:2017-02-08, yesterday close:10.37, today close:10.51, ma20:10.5\n",
      "idx:2017-02-09, yesterday close:10.51, today close:10.77, ma20:10.478\n",
      "2017-02-09买入，open:10.48，账户剩余：842.00，持仓：1800.00，总资产：19706.00\n",
      "idx:2017-02-10, yesterday close:10.77, today close:10.55, ma20:10.446\n",
      "idx:2017-02-14, yesterday close:10.62, today close:10.54, ma20:10.398\n",
      "idx:2017-02-15, yesterday close:10.54, today close:10.3, ma20:10.372\n",
      "idx:2017-02-16, yesterday close:10.3, today close:10.3, ma20:10.357\n",
      "2017-02-16卖出，open:10.25，账户剩余：19292.00，持仓： 0.00\n",
      "idx:2017-02-17, yesterday close:10.3, today close:10.25, ma20:10.369\n",
      "idx:2017-02-21, yesterday close:10.43, today close:10.48, ma20:10.403\n",
      "2017-02-21买入，open:10.38，账户剩余：608.00，持仓：1800.00，总资产：19292.00\n",
      "idx:2017-02-22, yesterday close:10.48, today close:10.56, ma20:10.431\n",
      "idx:2017-02-23, yesterday close:10.56, today close:10.53, ma20:10.449\n",
      "idx:2017-02-24, yesterday close:10.53, today close:10.62, ma20:10.466\n",
      "idx:2017-02-28, yesterday close:10.5, today close:10.59, ma20:10.504\n",
      "2017-02-28卖出，open:10.50，账户剩余：19508.00，持仓： 0.00\n",
      "idx:2017-03-01, yesterday close:10.59, today close:10.59, ma20:10.523\n",
      "2017-03-01买入，open:10.67，账户剩余：302.00，持仓：1800.00，总资产：19508.00\n",
      "idx:2017-03-02, yesterday close:10.59, today close:10.5, ma20:10.489\n",
      "idx:2017-03-03, yesterday close:10.5, today close:10.65, ma20:10.507\n",
      "2017-03-03卖出，open:10.49，账户剩余：19184.00，持仓： 0.00\n",
      "idx:2017-03-07, yesterday close:10.89, today close:11.07, ma20:10.563\n",
      "2017-03-07买入，open:10.88，账户剩余：688.00，持仓：1700.00，总资产：19184.00\n",
      "idx:2017-03-08, yesterday close:11.07, today close:10.91, ma20:10.583\n",
      "idx:2017-03-09, yesterday close:10.91, today close:10.81, ma20:10.585\n",
      "idx:2017-03-10, yesterday close:10.81, today close:10.71, ma20:10.593\n",
      "idx:2017-03-14, yesterday close:11.0, today close:10.83, ma20:10.626\n",
      "idx:2017-03-15, yesterday close:10.83, today close:10.79, ma20:10.651\n",
      "idx:2017-03-16, yesterday close:10.79, today close:11.01, ma20:10.686\n",
      "idx:2017-03-17, yesterday close:11.01, today close:10.9, ma20:10.719\n",
      "idx:2017-03-21, yesterday close:10.92, today close:10.84, ma20:10.761\n",
      "idx:2017-03-22, yesterday close:10.84, today close:10.64, ma20:10.765\n",
      "idx:2017-03-23, yesterday close:10.64, today close:10.74, ma20:10.776\n",
      "2017-03-23卖出，open:10.65，账户剩余：18793.00，持仓： 0.00\n",
      "idx:2017-03-24, yesterday close:10.74, today close:11.17, ma20:10.803\n",
      "idx:2017-03-28, yesterday close:11.36, today close:11.29, ma20:10.881\n",
      "2017-03-28买入，open:11.30，账户剩余：713.00，持仓：1600.00，总资产：18793.00\n",
      "idx:2017-03-29, yesterday close:11.29, today close:11.12, ma20:10.908\n",
      "idx:2017-03-30, yesterday close:11.12, today close:11.03, ma20:10.934\n",
      "idx:2017-03-31, yesterday close:11.03, today close:11.02, ma20:10.953\n",
      "idx:2017-04-06, yesterday close:11.12, today close:11.27, ma20:10.974\n",
      "idx:2017-04-07, yesterday close:11.27, today close:11.24, ma20:10.991\n",
      "idx:2017-04-11, yesterday close:10.97, today close:11.05, ma20:11.016\n",
      "2017-04-11卖出，open:10.91，账户剩余：18169.00，持仓： 0.00\n",
      "idx:2017-04-12, yesterday close:11.05, today close:10.88, ma20:11.01\n",
      "2017-04-12买入，open:11.05，账户剩余：489.00，持仓：1600.00，总资产：18169.00\n",
      "idx:2017-04-13, yesterday close:10.88, today close:10.83, ma20:11.01\n",
      "2017-04-13卖出，open:10.85，账户剩余：17849.00，持仓： 0.00\n",
      "idx:2017-04-14, yesterday close:10.83, today close:10.55, ma20:10.998\n",
      "idx:2017-04-18, yesterday close:10.42, today close:10.45, ma20:10.946\n",
      "idx:2017-04-19, yesterday close:10.45, today close:10.2, ma20:10.91\n",
      "idx:2017-04-20, yesterday close:10.2, today close:10.12, ma20:10.874\n",
      "idx:2017-04-21, yesterday close:10.12, today close:9.99, ma20:10.841\n",
      "idx:2017-04-25, yesterday close:9.77, today close:9.9, ma20:10.729\n",
      "idx:2017-04-26, yesterday close:9.9, today close:10.3, ma20:10.676\n",
      "idx:2017-04-27, yesterday close:10.3, today close:10.34, ma20:10.629\n",
      "idx:2017-04-28, yesterday close:10.34, today close:10.41, ma20:10.593\n",
      "idx:2017-05-03, yesterday close:10.25, today close:10.28, ma20:10.517\n",
      "idx:2017-05-04, yesterday close:10.28, today close:10.37, ma20:10.48\n",
      "idx:2017-05-05, yesterday close:10.37, today close:10.31, ma20:10.432\n",
      "idx:2017-05-09, yesterday close:10.26, today close:10.2, ma20:10.344\n",
      "idx:2017-05-10, yesterday close:10.2, today close:9.95, ma20:10.289\n",
      "idx:2017-05-11, yesterday close:9.95, today close:9.98, ma20:10.244\n",
      "idx:2017-05-12, yesterday close:9.98, today close:9.96, ma20:10.201\n",
      "idx:2017-05-16, yesterday close:10.05, today close:10.2, ma20:10.165\n",
      "idx:2017-05-17, yesterday close:10.2, today close:10.16, ma20:10.15\n",
      "2017-05-17买入，open:10.18，账户剩余：543.00，持仓：1700.00，总资产：17849.00\n",
      "idx:2017-05-18, yesterday close:10.16, today close:9.97, ma20:10.139\n",
      "idx:2017-05-19, yesterday close:9.97, today close:10.02, ma20:10.134\n",
      "2017-05-19卖出，open: 9.97，账户剩余：17492.00，持仓： 0.00\n",
      "idx:2017-05-23, yesterday close:9.94, today close:9.88, ma20:10.137\n",
      "idx:2017-05-24, yesterday close:9.88, today close:9.9, ma20:10.137\n",
      "idx:2017-05-25, yesterday close:9.9, today close:9.96, ma20:10.12\n",
      "idx:2017-05-26, yesterday close:9.96, today close:9.87, ma20:10.096\n",
      "idx:2017-06-01, yesterday close:9.77, today close:9.28, ma20:10.016\n",
      "idx:2017-06-02, yesterday close:9.28, today close:9.25, ma20:9.964\n",
      "idx:2017-06-06, yesterday close:9.3, today close:9.37, ma20:9.864\n",
      "idx:2017-06-07, yesterday close:9.37, today close:9.54, ma20:9.828\n",
      "idx:2017-06-08, yesterday close:9.54, today close:9.43, ma20:9.789\n",
      "idx:2017-06-09, yesterday close:9.43, today close:9.42, ma20:9.763\n",
      "idx:2017-06-13, yesterday close:9.02, today close:9.1, ma20:9.672\n",
      "idx:2017-06-14, yesterday close:9.1, today close:9.15, ma20:9.627\n",
      "idx:2017-06-15, yesterday close:9.15, today close:9.42, ma20:9.588\n",
      "idx:2017-06-16, yesterday close:9.42, today close:9.35, ma20:9.547\n",
      "idx:2017-06-20, yesterday close:9.47, today close:9.78, ma20:9.51\n",
      "idx:2017-06-21, yesterday close:9.78, today close:9.65, ma20:9.496\n",
      "2017-06-21买入，open: 9.70，账户剩余：32.00，持仓：1800.00，总资产：17492.00\n",
      "idx:2017-06-22, yesterday close:9.65, today close:9.42, ma20:9.473\n",
      "idx:2017-06-23, yesterday close:9.42, today close:9.55, ma20:9.455\n",
      "2017-06-23卖出，open: 9.40，账户剩余：16952.00，持仓： 0.00\n",
      "idx:2017-06-27, yesterday close:9.8, today close:9.98, ma20:9.453\n",
      "2017-06-27买入，open:10.40，账户剩余：312.00，持仓：1600.00，总资产：16952.00\n",
      "idx:2017-06-28, yesterday close:9.98, today close:9.81, ma20:9.455\n",
      "idx:2017-06-29, yesterday close:9.81, today close:9.93, ma20:9.487\n",
      "idx:2017-06-30, yesterday close:9.93, today close:10.18, ma20:9.534\n",
      "idx:2017-07-04, yesterday close:10.12, today close:9.98, ma20:9.605\n",
      "idx:2017-07-05, yesterday close:9.98, today close:10.02, ma20:9.629\n",
      "idx:2017-07-06, yesterday close:10.02, today close:10.03, ma20:9.659\n",
      "idx:2017-07-07, yesterday close:10.03, today close:10.43, ma20:9.71\n",
      "idx:2017-07-11, yesterday close:10.22, today close:9.98, ma20:9.814\n",
      "idx:2017-07-12, yesterday close:9.98, today close:10.05, ma20:9.859\n",
      "idx:2017-07-13, yesterday close:10.05, today close:10.02, ma20:9.889\n",
      "idx:2017-07-14, yesterday close:10.02, today close:9.91, ma20:9.917\n",
      "idx:2017-07-18, yesterday close:9.21, today close:9.34, ma20:9.882\n",
      "2017-07-18卖出，open: 9.18，账户剩余：15000.00，持仓： 0.00\n",
      "idx:2017-07-19, yesterday close:9.34, today close:9.48, ma20:9.873\n",
      "idx:2017-07-20, yesterday close:9.48, today close:9.56, ma20:9.88\n",
      "idx:2017-07-21, yesterday close:9.56, today close:9.52, ma20:9.879\n",
      "idx:2017-07-25, yesterday close:9.39, today close:9.32, ma20:9.825\n",
      "idx:2017-07-26, yesterday close:9.32, today close:9.3, ma20:9.8\n",
      "idx:2017-07-27, yesterday close:9.3, today close:9.49, ma20:9.778\n",
      "idx:2017-07-28, yesterday close:9.49, today close:9.34, ma20:9.736\n",
      "idx:2017-08-01, yesterday close:9.38, today close:9.53, ma20:9.676\n",
      "idx:2017-08-02, yesterday close:9.53, today close:9.35, ma20:9.643\n",
      "idx:2017-08-03, yesterday close:9.35, today close:9.4, ma20:9.611\n",
      "idx:2017-08-04, yesterday close:9.4, today close:9.29, ma20:9.554\n",
      "idx:2017-08-08, yesterday close:9.33, today close:9.34, ma20:9.478\n",
      "idx:2017-08-09, yesterday close:9.34, today close:9.33, ma20:9.442\n",
      "idx:2017-08-10, yesterday close:9.33, today close:9.38, ma20:9.41\n",
      "idx:2017-08-11, yesterday close:9.38, today close:9.25, ma20:9.377\n",
      "2017-08-11买入，open: 9.37，账户剩余： 8.00，持仓：1600.00，总资产：15000.00\n",
      "idx:2017-08-15, yesterday close:9.43, today close:9.49, ma20:9.395\n",
      "idx:2017-08-16, yesterday close:9.49, today close:9.63, ma20:9.403\n",
      "idx:2017-08-17, yesterday close:9.63, today close:9.76, ma20:9.413\n",
      "idx:2017-08-18, yesterday close:9.76, today close:9.63, ma20:9.418\n",
      "idx:2017-08-22, yesterday close:9.68, today close:9.61, ma20:9.447\n",
      "idx:2017-08-23, yesterday close:9.61, today close:9.58, ma20:9.461\n",
      "idx:2017-08-24, yesterday close:9.58, today close:9.56, ma20:9.465\n",
      "idx:2017-08-25, yesterday close:9.56, today close:9.66, ma20:9.481\n",
      "idx:2017-08-29, yesterday close:9.8, today close:9.75, ma20:9.513\n",
      "idx:2017-08-30, yesterday close:9.75, today close:9.76, ma20:9.533\n",
      "idx:2017-08-31, yesterday close:9.76, today close:9.79, ma20:9.553\n",
      "idx:2017-09-01, yesterday close:9.79, today close:9.83, ma20:9.58\n",
      "idx:2017-09-05, yesterday close:10.09, today close:10.41, ma20:9.671\n",
      "idx:2017-09-06, yesterday close:10.41, today close:10.42, ma20:9.726\n",
      "idx:2017-09-07, yesterday close:10.42, today close:10.31, ma20:9.772\n",
      "idx:2017-09-08, yesterday close:10.31, today close:10.42, ma20:9.831\n",
      "idx:2017-09-12, yesterday close:10.54, today close:10.38, ma20:9.931\n",
      "idx:2017-09-13, yesterday close:10.38, today close:10.31, ma20:9.965\n",
      "idx:2017-09-14, yesterday close:10.31, today close:10.46, ma20:10.0\n",
      "idx:2017-09-15, yesterday close:10.46, today close:10.18, ma20:10.027\n",
      "idx:2017-09-19, yesterday close:10.65, today close:10.46, ma20:10.118\n",
      "idx:2017-09-20, yesterday close:10.46, today close:11.51, ma20:10.215\n",
      "idx:2017-09-21, yesterday close:11.51, today close:12.66, ma20:10.37\n",
      "idx:2017-09-22, yesterday close:12.66, today close:12.7, ma20:10.522\n",
      "idx:2017-09-26, yesterday close:11.85, today close:12.07, ma20:10.74\n",
      "idx:2017-09-27, yesterday close:12.07, today close:12.1, ma20:10.857\n",
      "idx:2017-09-28, yesterday close:12.1, today close:12.11, ma20:10.973\n",
      "idx:2017-09-29, yesterday close:12.11, today close:12.6, ma20:11.112\n",
      "idx:2017-10-10, yesterday close:12.82, today close:12.46, ma20:11.351\n",
      "idx:2017-10-11, yesterday close:12.46, today close:11.91, ma20:11.425\n",
      "idx:2017-10-12, yesterday close:11.91, today close:11.94, ma20:11.507\n",
      "idx:2017-10-13, yesterday close:11.94, today close:11.93, ma20:11.582\n",
      "idx:2017-10-17, yesterday close:11.4, today close:11.54, ma20:11.683\n",
      "2017-10-17卖出，open:11.40，账户剩余：18248.00，持仓： 0.00\n",
      "idx:2017-10-18, yesterday close:11.54, today close:11.13, ma20:11.724\n",
      "idx:2017-10-19, yesterday close:11.13, today close:11.26, ma20:11.764\n",
      "idx:2017-10-20, yesterday close:11.26, today close:11.47, ma20:11.829\n",
      "idx:2017-10-24, yesterday close:11.36, today close:11.48, ma20:11.915\n",
      "idx:2017-10-25, yesterday close:11.48, today close:11.51, ma20:11.915\n",
      "idx:2017-10-26, yesterday close:11.51, today close:11.55, ma20:11.86\n",
      "idx:2017-10-27, yesterday close:11.55, today close:11.13, ma20:11.781\n",
      "idx:2017-10-31, yesterday close:10.82, today close:10.9, ma20:11.671\n",
      "idx:2017-11-01, yesterday close:10.9, today close:11.14, ma20:11.623\n",
      "idx:2017-11-02, yesterday close:11.14, today close:10.99, ma20:11.567\n",
      "idx:2017-11-03, yesterday close:10.99, today close:12.09, ma20:11.542\n",
      "账户剩余：18248.00，持仓： 0.00\n"
     ]
    }
   ],
   "source": [
    "# read dataframe from csv.\n",
    "# allData = ts.get_hist_data('002156',start='2015-01-01');\n",
    "# allData = pd.read_csv('002156.csv');\n",
    "allData = pd.read_csv(\"002156.csv\", index_col=\"date\")\n",
    "allData = allData.sort_index(ascending=True)\n",
    "five = allData.head(5)\n",
    "five = allData\n",
    "userCount = 20000\n",
    "stkLevel = 0\n",
    "yesterdayClose = 0\n",
    "ma20 = 0\n",
    "open = 0\n",
    "yesterday = \"\"\n",
    "for idx in five.index:\n",
    "    try:\n",
    "        yesterday = (datetime.strptime(idx, '%Y-%m-%d') - timedelta(days=1)).strftime('%Y-%m-%d')\n",
    "        yesterdayClose = five.loc[yesterday,'close']\n",
    "        ma20 = five.loc[idx,'ma20']\n",
    "        print(\"idx:%s, yesterday close:%s, today close:%s, ma20:%s\" % (idx, yesterdayClose, five.loc[idx,'close'], ma20))\n",
    "        open = five.loc[idx,'open']\n",
    "        if yesterdayClose > ma20 :\n",
    "            stks = allowStkCounts(userCount, open)\n",
    "            if stks > 0 :\n",
    "                stkLevel = stkLevel + stks;\n",
    "                userCount = userCount - stks*open\n",
    "                print(\"%s买入，open:%5.2f，账户剩余：%5.2f，持仓：%5.2f，总资产：%5.2f\" % (idx, open, userCount, stkLevel, userCount+stkLevel*open))\n",
    "        else :\n",
    "            if stkLevel > 0 :\n",
    "                userCount = userCount + stkLevel*open\n",
    "                stkLevel = 0\n",
    "                print(\"%s卖出，open:%5.2f，账户剩余：%7.2f，持仓：%5.2f\" % (idx, open, userCount, stkLevel))\n",
    "    except KeyError as ke:\n",
    "        pass\n",
    "    except Error as e:\n",
    "        print(e)\n",
    "print(\"账户剩余：%5.2f，持仓：%5.2f\" % (userCount, stkLevel))\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
